typedef struct
{
    int* a;
    int front;
    int rear;
    int k;
} MyCircularQueue;


MyCircularQueue* myCircularQueueCreate(int k)
{
    MyCircularQueue* cq = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    if (cq == NULL)
    {
        perror("malloc fail");
        exit(1);
    }
    cq->a = (int*)malloc(sizeof(int) * (k + 1));
    cq->front = cq->rear = 0;
    cq->k = k;
    return cq;
}

bool myCircularQueueIsEmpty(MyCircularQueue* cq)
{
    return (cq->front == cq->rear);
}

bool myCircularQueueIsFull(MyCircularQueue* cq)
{
    return (cq->rear + 1) % (cq->k + 1) == cq->front;
}

bool myCircularQueueEnQueue(MyCircularQueue* cq, int value)
{
    if (myCircularQueueIsFull(cq))
        return false;
    cq->a[cq->rear++] = value;
    cq->rear %= cq->k + 1;
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj)
{
    if (myCircularQueueIsEmpty(obj))
        return false;
    ++obj->front;
    obj->front %= obj->k + 1;
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj)
{
    if (myCircularQueueIsEmpty(obj))
        return -1;
    return obj->a[obj->front];
}

int myCircularQueueRear(MyCircularQueue* obj)
{
    if (myCircularQueueIsEmpty(obj))
        return -1;
    return obj->a[(obj->rear + obj->k) % (obj->k + 1)];
}

void myCircularQueueFree(MyCircularQueue* obj)
{
    free(obj->a);
    free(obj);
}